package com.jyskkebank.android.util;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

import android.app.AlertDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.RelativeLayout;

import com.jyskkebank.android.toggl.R;
import com.jyskkebank.android.toggl.LoginActivity;

public class Utility {

	public static void showErrorPopup(final Context mContext) {
		AlertDialog.Builder errorPopup = new AlertDialog.Builder(mContext);
		errorPopup.setInverseBackgroundForced(false);
		errorPopup.setTitle("Error")

		.setMessage("Please enter Username/Password first !")
				.setPositiveButton("OK", null).show();
//
//		LayoutInflater inflater = (LayoutInflater) mContext
//				.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
//		View view = inflater.inflate(R.layout.errorpopup, null);
//		errorPopup.setView(view);

	}
	
	public static void showAbout(final Context mContext) {
		AlertDialog.Builder errorPopup = new AlertDialog.Builder(mContext);
		errorPopup.setInverseBackgroundForced(false);
		errorPopup.setTitle("About")

		.setMessage("JBToggl is a time tracking software that will trank your time anywhere on anything: Mac, PC, iPhone, iPad, iPod, or Android. This software is created by i-bank team of Jyske Bank and the contributors are Amanpreet , Anshita , Neeraj , Pankaj, Sangeeta ")
				.setPositiveButton("OK", null).show();
//
//		LayoutInflater inflater = (LayoutInflater) mContext
//				.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
//		View view = inflater.inflate(R.layout.errorpopup, null);
//		errorPopup.setView(view);

	}

	public static boolean validateBeforeLogin(String userName, String password) {
		boolean result = false;
		if (validateUserName(userName) && password != null
				&& !password.equals("")) {
			result = true;
		}
		return result;
	}

	private static boolean validateUserName(String userName) {
		Pattern p = Pattern.compile("[a-zA-Z0-9._-]+@[a-zA-Z0-9._-]+\\.[a-zA-Z]{2,4}$");
		Matcher m = p.matcher(userName);
		return m.matches();
	}
}
